/**
 * JS
 */
angular.module('usercenter.module.myview', [])

    .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('ucboot.myview', {
                url: '/myview',
                templateUrl: uc_templateprefix + 'myview/myview.html',
                controller: 'MyviewController'
            })
            .state('feedback', {
                url: '/feedback',
                templateUrl: uc_templateprefix + 'myview/feedback.html',
                controller: 'FeedbackController'
            })
            .state('address', {
                url: '/address',
                resolve: {
                    address_list: ['AddressService', function (AddressService) {
                        var addr = AddressService.get_address();
                        if (typeof(addr) == 'object') {
                            return addr.$promise;
                        }
                        return addr;
                    }]
                },
                templateUrl: uc_templateprefix + 'myview/address.html',
                controller: 'AddressController'
            })
            .state('newaddress', {
                url: '/newaddress/:orderid',
                resolve: {
                    address_list: ['AddressService', function (AddressService) {
                        var addr = AddressService.get_address();
                        if (typeof(addr) == 'object') {
                            return addr.$promise;
                        }
                        return addr;
                    }]
                },
                templateUrl: uc_templateprefix + 'myview/newaddress.html',
                controller: 'NewAddressController'
            })

            .state('reviseaddress', {
                url: '/reviseaddress/:contactid',
                /*params:{address:null},*/
                templateUrl: uc_templateprefix + 'myview/reviseaddress.html',
                controller: 'ReviseAddressController'
            })

            .state('account_setting', {
                url: '/account_setting',
                templateUrl: uc_templateprefix + 'myview/account_setting.html',
                controller: 'AccountSettingController'
            })
            .state('password', {
                url: '/password',
                templateUrl: uc_templateprefix + 'myview/password.html',
                controller: 'PasswordController'
            })
            .state('usermembers', {
                url: '/usermembers',
                templateUrl: uc_templateprefix + 'myview/usermembers.html',
                controller: 'UserMembersController'
            })
            .state('accountname', {
                url: '/accountname',
                templateUrl: uc_templateprefix + 'myview/accountname.html',
                controller: 'AccountNameController'
            })
            .state('ucboot.copyright', {
                url: '/copyright',
                templateUrl: uc_templateprefix + 'myview/copyright.html',
                controller: 'CopyrightController'
            })
            .state('userpoint', {
                url: '/userpoint',
                templateUrl: uc_templateprefix + 'myuserpoint/userpoint.html',
                controller: 'UserpointController'
            })
            .state('changepoint', {
                url: '/changepoint',
                templateUrl: uc_templateprefix + 'myuserpoint/changepoint.html',
                controller: 'ChangepointController'
            })
        ;
    }])
    .controller('MyviewController', ['$scope', '$state', 'AuthService', function ($scope, $state, AuthService) {
        UserChange(2);
        the_top();
        $scope.uc_mallurl = projectBaseUrl;
        var id = AuthService.getUserid();
        if (id == '') {
            $state.go('ucboot.login', {way: ''});
        } else {
            $scope.username = AuthService.getUsername();
            AuthService.getUserMessg().$promise.then(function (data) {
                $scope.user = data;
            });

            $scope.logout = function () {
                AuthService.logout();
                $scope.username = AuthService.getUsername();
            };

            $scope.headimg = function () {
                var id = AuthService.getUserid();
                $state.go('account_setting');

            }
            $scope.toFeedback = function () {
                $state.go('feedback');
            }

            /* $scope.toRecgoods = function(active){
             var id = AuthService.getUserid();
             $state.go('orderlist',{active : active});

             }*/
            $scope.toAccount_setting = function () {
                var id = AuthService.getUserid();
                $state.go('account_setting');
            }
            $scope.toAddress = function () {
                var id = AuthService.getUserid();
                $state.go('address');
            }
            $scope.toMywealth = function () {
                var id = AuthService.getUserid();
                $state.go('mywealth');
            }
            $scope.toCopyright = function () {
                var id = AuthService.getUserid();
                $state.go('ucboot.copyright');
            }
            $scope.touserpoints = function () {
                $state.go('userpoint');
            }
        }
        ;

    }])

    //收货地址页面控制
    .controller('AddressController', ['$scope', '$state', 'AddressService', 'address_list', function ($scope, $state, AddressService, address_list) {
        dismiss();
        //获取有的地址信息
        $scope.address_list = address_list;
        $scope.defaultAddressCss = function () {
            var address = document.getElementsByName('address');
            var defaultText = document.querySelectorAll('.consumer_condition')
            address[0].checked = true;
            defaultText[0].innerHTML = '默认地址'
        }
        /*if ($scope.address_list == false) {
         input_alert("您还未添加收货地址", 1000);
         }*/
        //修改地址信息
        $scope.revise = function (address) {
            for (var i = 0; i < $scope.address_list.length; i++) {
                if ($scope.address_list[i].contactid == address.contactid) {
                    $state.go("reviseaddress", {contactid: address.contactid})
                }
            }
        }

        //删除地址
        $scope.myque_remove = function (contactid) {
            $(".contain-item").fadeIn();
            $scope.remove = function () {
                //这个是地列表，这是一个数组所有要遍历找到id节点
                var indextodelete = -1;
                for (var i = 0; i < $scope.address_list.length; i++) {
                    if ($scope.address_list[i].contactid == contactid) {
                        //从数组中删除这个id的�??
                        indextodelete = i;
                        break;
                    }
                }
                if (indextodelete >= 0) {
                    $scope.address_list.splice(indextodelete, 1);
                }
                AddressService.remove(contactid).$promise.then(function (data) {
                    $(".contain-item").fadeOut();
                    input_alert("删除地址成功", 1000);
                }, function (data) {
                    input_alert("删除失败", 1000);
                })
            }
        }
        //设置默认地址
        $scope.updateDeafult = function (address) {
            var defaultText = $("#default" + address.contactid);
            if (defaultText.html() == '设置默认') {
                toastHtml('设置中', true);
                AddressService.update(address).$promise.then(function (data) {
                    //input_alert("设置成功");
                    var consumer_condition = $(".consumer_condition");
                    consumer_condition.html('设置默认');
                    defaultText.html('默认地址');
                    toastHtml('', false);
                }, function (error) {
                    input_alert("设置失败");
                });
            }
        }
    }])

    //新增收货页面地址
    .controller('NewAddressController', ['$scope',  '$window', 'AddressService', function ($scope, $window, AddressService) {
        $scope.provinceList = [];
        $scope.cityList = [];
        $scope.countyList = [];
        var district = {
            province: '',
            city: '',
            county: ''
        }
        var districtChoose = $("#districtChoose").find(".districtChoose");
        $scope.newadr_hide = function () {
            click_showadr(".newaddress_height_listbg", ".newaddress_height_list", "#hidval");
            if ($scope.provinceList.length == 0) {
                AddressService.getProvince().$promise.then(function (data) {
                    $scope.provinceList = data;
                    districtChoose.hide();
                    districtChoose[0].style.display = 'block';
                })
            }
        }
        $scope.newaddress = {};
        $scope.save_address = function () {
            if (Object.keys($scope.newaddress).length == 0) {
                input_alert("请填写正确信息！");
            } else {
                $scope.newaddress.sex = $('input:radio:checked').val();
                AddressService.add_address($scope.newaddress, function () {
                    input_alert('添加地址成功', 1000);
                    setTimeout(function () {
                        $window.history.back();
                    }, 1000);
                });
            }
        }
        AddressService.getProvince().$promise.then(function (data) {
            $scope.provinceList = data;
            districtChoose.hide();
            districtChoose[0].style.display = 'block';
        })
        $scope.chooseProvince = function (province) {
            district.province = province.name;
            district.city = '';
            district.county = '';
            if (district.province == '台湾省' || district.province == '香港特别行政区' || district.province == '澳门特别行政区') {
                $("#district").html(district.province);
                $("#province").find('span')[0].innerHTML = province.name + "";
                $scope.newaddress.area = district.province;
                click_showadr(".newaddress_height_listbg", ".newaddress_height_list", "#hidval");
            } else {
                var name = district.province + district.city + district.county;
                $("#province").find('span')[0].innerHTML = province.name + "";
                AddressService.getCity(province.provinceid).$promise.then(function (data) {
                    $scope.cityList = data;
                    $("#chooseAddr").html('<div id="province" class="choose" onclick="chooseDistrict(this,1)"> <span>' + district.province + '</span> </div><div id="city" class="choose active" onclick="chooseDistrict(this,2)"><span>请选择</span></div>');
                    districtChoose.hide();
                    districtChoose[1].style.display = 'block';
                })
            }
        }
        $scope.chooseCity = function (city) {
            district.city = city.name;
            district.county = '';
            var name = district.province + district.city + district.county;
            $("#city").find('span')[0].innerHTML = city.name + "";
            AddressService.getCounty(city.cityid).$promise.then(function (data) {
                $scope.countyList = data;
                $("#chooseAddr").html('<div id="province" class="choose" onclick="chooseDistrict(this,1)"> <span>' + district.province + '</span> </div><div id="city" class="choose" onclick="chooseDistrict(this,2)"><span>' + district.city + '</span></div><div id="county" class="choose active" onclick="chooseDistrict(this,3)"><span>请选择</span></div>');
            })
            districtChoose.hide();
            districtChoose[2].style.display = 'block';
        }
        $scope.chooseCounty = function (county) {
            district.county = county.name;
            var name = district.province + district.city + district.county;
            $("#district").html(name);
            $("#county").find('span')[0].innerHTML = county.name + "";
            click_showadr(".newaddress_height_listbg", ".newaddress_height_list", "#hidval");
            $scope.newaddress.area = name;
        }
    }])
    //修改收货页面地址
    .controller('ReviseAddressController', ['$scope', '$state', '$stateParams', '$window', 'AddressService', function ($scope, $state, $stateParams, $window, AddressService) {
        $scope.provinceList = [];
        $scope.cityList = [];
        $scope.countyList = [];
        var district = {
            province: '',
            city: '',
            county: ''
        }
        var districtChoose = $("#districtChoose").find(".districtChoose");
        $scope.newadr_hide = function () {
            click_showadr(".newaddress_height_listbg", ".newaddress_height_list", "#hidval");
            if ($scope.provinceList.length == 0) {
                AddressService.getProvince().$promise.then(function (data) {
                    $scope.provinceList = data;
                    districtChoose.hide();
                    districtChoose[0].style.display = 'block';
                })
            }
        }
        $scope.contactid = $stateParams.contactid;
        AddressService.get_addressbyid($scope.contactid).$promise.then(function (data) {
            $scope.address = data;
            if (data.sex == 1) {
                $('#male').attr("checked", "checked")
            }
            else if (data.sex == 2) {
                $('#female').attr("checked", "checked")
            }
        });
        $scope.revise_address = function () {
            $scope.address.sex = $('input:radio:checked').val();
            AddressService.revise($scope.address).$promise.then(function (data) {
                input_alert("修改地址成功", 1000);
                setTimeout(function () {
                    $window.history.back();
                }, 1000)
            }, function (data) {
                input_alert("修改失败", 1000);
            })
        }
        AddressService.getProvince().$promise.then(function (data) {
            $scope.provinceList = data;
            districtChoose.hide();
            districtChoose[0].style.display = 'block';
        })
        $scope.chooseProvince = function (province) {
            district.province = province.name;
            district.city = '';
            district.county = '';
            if (district.province == '台湾省' || district.province == '香港特别行政区' || district.province == '澳门特别行政区') {
                $("#district").html(district.province);
                $("#province").find('span')[0].innerHTML = province.name + "";
                $scope.address.area = district.province;
                click_showadr(".newaddress_height_listbg", ".newaddress_height_list", "#hidval");
            } else {
                var name = district.province + district.city + district.county;
                $("#province").find('span')[0].innerHTML = province.name + "";
                AddressService.getCity(province.provinceid).$promise.then(function (data) {
                    $scope.cityList = data;
                    $("#chooseAddr").html('<div id="province" class="choose" onclick="chooseDistrict(this,1)"> <span>' + district.province + '</span> </div><div id="city" class="choose active" onclick="chooseDistrict(this,2)"><span>请选择</span></div>');
                    districtChoose.hide();
                    districtChoose[1].style.display = 'block';
                })
            }
        }
        $scope.chooseCity = function (city) {
            district.city = city.name;
            district.county = '';
            var name = district.province + district.city + district.county;
            $("#city").find('span')[0].innerHTML = city.name + "";
            AddressService.getCounty(city.cityid).$promise.then(function (data) {
                $scope.countyList = data;
                $("#chooseAddr").html('<div id="province" class="choose" onclick="chooseDistrict(this,1)"> <span>' + district.province + '</span> </div><div id="city" class="choose" onclick="chooseDistrict(this,2)"><span>' + district.city + '</span></div><div id="county" class="choose active" onclick="chooseDistrict(this,3)"><span>请选择</span></div>');
            })
            districtChoose.hide();
            districtChoose[2].style.display = 'block';
        }
        $scope.chooseCounty = function (county) {
            district.county = county.name;
            var name = district.province + district.city + district.county;
            $("#district").html(name);
            $("#county").find('span')[0].innerHTML = county.name + "";
            click_showadr(".newaddress_height_listbg", ".newaddress_height_list", "#hidval");
            $scope.address.area = name;
        }
    }])

    //意见反馈控制
    .controller('FeedbackController', ['$scope', 'FeedbackService', function ($scope, FeedbackService) {
        $scope.content = '';

        $scope.feedback = function () {
            if ($scope.content == '') {
                input_alert('请填写你的意见?')
            }
            else {
                FeedbackService.subFeedback($scope.content);
                if (FeedbackService.content == null) {
                    input_alert('提交成功')
                    $scope.content = '';
                }
            }
        }
    }])

    .controller('AccountSettingController', ['$scope', '$state', '$rootScope', 'AuthService','UserbelongService', function ($scope, $state, $rootScope, AuthService,UserbelongService) {
        UserbelongService.getByid($storage.userId).$promise.then(function(data){
            $scope.belong = false;
        },function(){
            $scope.belong = true;
        });
        $scope.gotouserbelong =function(){
            if($scope.belong == false){
               $state.go("userbelong",{parm:1});
            }
            else{
                $state.go("userbelong",{parm:2});
            }
        }
        $scope.loadImageLocal = function () {
            //获取本地图片并显示在屏幕
            navigator.camera.getPicture(onLoadImageLocalSuccess, onLoadImageFail, {
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
                allowEdit: true
            });
        }
        $scope.loadImageUpload = function () {
            //拍照上传并显示在屏幕
            navigator.camera.getPicture(onLoadImageLocalSuccess, onLoadImageFail, {
                destinationType: Camera.DestinationType.FILE_URI,
                allowEdit: true
            });
        }
        //本地图片选择成功后回调此函数
        function onLoadImageLocalSuccess(imageURI) {
            var id = $scope.user.userid + "";
            var timestamp = new Date().getTime() + "";
            var options = new FileUploadOptions(); //文件参数选项
            options.fileKey = "file";//向服务端传递的file参数的parameter name
            options.fileName = id + timestamp + imageURI.substr(imageURI.lastIndexOf('/') + 1);//文件名
            options.mimeType = "image/jpeg";//文件格式，默认为image/jpeg
            var ft = new FileTransfer();//文件上传类
            ft.onprogress = function (progressEvt) {//显示上传进度条
                if (progressEvt.lengthComputable) {
                    navigator.notification.progressValue(Math.round(( progressEvt.loaded / progressEvt.total ) * 100));
                }
            }
            navigator.notification.progressStart("提醒", "当前上传进度");
            ft.upload(imageURI, encodeURI('http://114.55.90.31:81/ngbuc/fileupload/picupload'), function (data) {
                navigator.notification.progressStop();//停止进度条
                navigator.notification.alert("文件上传成功！", null, "提醒");
                $scope.user.logo = data.response;
                $(".contain-item").fadeOut();
                AuthService.setUserhead($scope.user,
                    function () {
                    },
                    function () {
                        input_alert("上传失败!!!");
                    });
            }, function () {
                input_alert("上传失败!!!");
            }, options);
        }

        function onLoadImageFail(message) {
            $(".contain-item").fadeOut();
            input_alert("操作失败：" + message)
            //navigator.notification.alert("操作失败：" + message, null, "警告");
        }

        $scope.loadImage = function () {
            if (appEnvironment == true) {
                $(".contain-item").fadeIn();
            } else {
                input_alert("头像在农归吧客户端设置")
            }
        }
        $(".contain-back").click(function () {
            $(".contain-item").fadeOut();
        });
        //根据登录ID 判断是否认证
        AuthService.get_userMembers().$promise.then(function (data_userM) {
            $scope.state = data_userM.userAuth;
        })
        AuthService.getUserMessg().$promise.then(function (data) {
            $scope.user = data;
        })
        $scope.disupload = function () {
            AuthService.getUserMessg().$promise.then(function (data) {
                $scope.user = data;
            });
            $(".thumbBox").css({"background-image": ""});
            $("#select_way").show();
            $("#user_logo").hide();
            $(".btnZoom").show();
            $("#btnCrop").show();
            $(".logo_btn").find("button").hide();
        }
    }])
    .controller('CopyrightController', ['$scope', 'AuthService', function ($scope, AuthService) {
        $scope.username = AuthService.getUsername();
    }])

    //修改登录密码
    .controller('PasswordController', ['$scope', '$state', 'AuthService', function ($scope, $state, AuthService) {
        $scope.username = AuthService.getUsername();
        $scope.password = {};
        $scope.restpassword = function () {
            $scope.password.oldPassword = $scope.oldpassword;
            $scope.password.newPassword = $scope.newpassword2;
            var old = $(".oldpassword").val();
            var new1 = $(".newpassword1").val();
            var new2 = $(".newpassword2").val();
            if ($scope.password.oldPassword == "" || $scope.password.oldPassword == null) {
                input_alert("请输入原始密码");
                $(".oldpassword").focus();
            }
            else if (old.length == 0) {
                input_alert("新密码不能为空！")
                $(".newpassword1").focus();
            }
            else if (new1.length < 8 || new1.length > 24) {
                input_alert("密码限8-24字符之间！")
                $(".newpassword1").focus();
                $(".newpassword1").select();
            }
            else if ($scope.newpassword1 == $scope.oldpassword) {
                input_alert("新密码不能与原密码相同");
                $(".newpassword1").focus();
                $(".newpassword1").select();
            } else if ($scope.newpassword2 != $scope.newpassword1) {
                input_alert("新密码两次输入不同");
                $(".newpassword2").focus();
                $(".newpassword2").select();
            }
            else {
                $scope.password.oldPassword = hex_md5($scope.password.oldPassword);
                $scope.password.newPassword = hex_md5($scope.password.newPassword);
                AuthService.restPassword($scope.password,
                    function () {
                        input_alert('修改成功', 1000);
                        setTimeout(function () {
                            $state.go("ucboot.login", {way: 0})
                        }, 1000)
                    }, function (data) {
                        input_alert(data.data.reason);
                        $(".oldpassword").select();
                        $(".oldpassword").focus();
                    })
            }
        }
    }])
    //会员认证
    .controller('UserMembersController', ['$scope', '$state', 'AuthService', function ($scope, $state, AuthService) {

        AuthService.get_userMembers().$promise.then(function (data_userM) {
            if (data_userM) {
                if (data_userM.userAuth == 0) {
                    AuthService.remove_userMembers();
                    return;
                    //认证失败 删除userMember数据
                }
                var ul_in = document.getElementById("push_liImage");
                $("#userMembers_sub").hide();
                $("#add_imageButton").hide();
                $(".members_head").hide();
                $scope.type = data_userM.picType;
                //选中营业执照选项
                if ($scope.type == 1) {
                    $("#addresstwo2").attr("checked", "checked");
                } else {
                    $("#addresstwo1").attr("checked", "checked");
                }
                $scope.picSrc = data_userM.picAuth.split('{{img:');
                for (var i = 0; i < ($scope.picSrc.length) - 1; i++) {
                    ul_in.innerHTML += "<li class='fatu1' style='float:left'><img id='conver_image" + i + "' src=" + $scope.picSrc[i] + "></li>";
                }
            }
        })

        var success_func = function () {
            input_alert("提交成功");
            setTimeout(function () {
                $state.go("account_setting");
            }, 1000)
        }
        var error_func = function () {
            input_alert("提交失败");
        }
        $scope.filesList = [];//存储files对象
        //在界面显示要上传的多图片
        $scope.setImage = function (obj) {
            var i = 0;
            var a = 0;
            var ul_in = document.getElementById("push_liImage");
            if (obj.files.length == 0) {
                return;
            }
            var fileList = obj.files;
            //校验图片
            if (checkPic(obj) == 1) {
                return;
            }
            if (fileList.length > 3) {
                input_alert("图片最多只能传3张", 2000);
                return;
            }
            $scope.deal_picture = function () {
                if (fileList[i]) {
                    $scope.filesList.push(fileList[i]);
                    a = $scope.filesList.length;
                    if (fileList[i].size > 2097152) {
                        input_alert("上传图片最大为2M", 2000);
                        return;
                    }
                    var reader = new FileReader();
                    reader.onload = function (evt) {
                        // 处理下配置参数和格式的html
                        ul_in.innerHTML += "<li id=" + a + " class='fatu1' style='float:left' onclick=angular.element(this).scope().remove_picture(this," + a + ")><img src=" + evt.target.result + ">";

                        i++;
                        // 再接着调用此方法递归组成可以预览的html
                        var arrLi = ul_in.getElementsByTagName('li');
                        if (arrLi.length == 3) {
                            $("#add_imageButton").hide();
                            return;
                        }
                        $scope.deal_picture();
                    }
                    reader.readAsDataURL(fileList[i]);
                } else {
                    return;
                }
            }
            $scope.deal_picture();
        }
        //上传图片
        $scope.uplo_pictuers = function () {
            var picture = document.getElementById("push_liImage");
            var arrLi = picture.getElementsByTagName('li');
            $scope.check_val = $('input:radio:checked').val();
            $scope.arrSrc = "";
            if (!$scope.check_val) {
                input_alert("请选择照片类型", 2000);
                return;
            }
            if (arrLi.length == 0) {
                input_alert("请上传图片", 2000);
                return;
            }
            var i = 0;
            $scope.abc = function () {
                var push_img = arrLi[i].getElementsByTagName('img');
                var b = arrLi[i].id;//$scope.filesList数组的的下标
                $scope.imageSrc = push_img[0].src;
                $scope.files = $scope.filesList[b - 1];
                $scope.imageName = $scope.filesList[b - 1].name;
                AuthService.uploadFile($scope.imageSrc, $scope.files, $scope.imageName).then(function (data) {
                    $scope.arrSrc += data + "{{img:";
                    i++;
                    if (i < arrLi.length) {
                        $scope.abc();
                    } else {
                        // 走到这里说明图片已经上传完毕
                        $scope.filesList = [];
                        $scope.addCompleteQue($scope.arrSrc, $scope.check_val);
                        return;
                    }
                });
            }
            $scope.abc();
        };
        //信息+图片路径
        $scope.addCompleteQue = function (strUrl, val) {
            $scope.userMember = {};
            $scope.userMember.picType = val;
            $scope.userMember.picAuth = strUrl;
            AuthService.save_userMembers($scope.userMember, success_func, error_func).$promise.then(function (data_userM) {
            });
        };
        //删除图片
        var remove_liObj = null;// 记录要删除的obj对象
        var mark = "";// 记录要删除图片的$scope.filesList数组的下标
        $scope.remove_picture = function (obj, a) {
            remove_liObj = "";
            $(".contain-item").fadeIn();
            remove_liObj = obj
            mark = a - 1;
        }
        $scope.remove_sure = function () {
            remove_liObj.remove();
            delete $scope.filesList[mark];
            //$scope.filesList.splice(mark,1);
            $(".contain-item").fadeOut();
            var ul_in = document.getElementById("push_liImage");
            var arrLi = ul_in.getElementsByTagName('li');
            if (arrLi.length < 3) {
                $("#add_imageButton").show();
            }
        }
    }])
    //修改用户�?
    .controller('AccountNameController', ['$scope', '$state', 'AuthService', function ($scope, $state, AuthService) {
        $scope.username = AuthService.getUsername();
        $scope.getUserMessg = AuthService.getUserMessg();
        $scope.sure = function () {
            var nam = $(".newname").val();
            var fist = nam.substring(1, 0);
            if (nam.length == 0) {
                input_alert("用户名不能为空！")
                $(".newname").focus()
            }
            else if (nam.length < 2 || nam.length > 16) {
                input_alert("用户名限2-16字符之间")
                $(".name").focus()
                $(".name").select()
            }
            else if (!fist.match(/^[\u4E00-\u9FA5a-zA-Z]/)) {
                input_alert("用户名只能以英文字母或汉字开头！")
                $(".name").focus()
                $(".name").select()
            }
            else if (!nam.match(/^[\u4E00-\u9FA5a-zA-Z0-9]+$/)) {
                $(".name").focus()
                $(".name").select()
                input_alert("用户名不能为特殊符号")
            } else {
                $scope.getUserMessg.name = $scope.username;
                AuthService.resetName($scope.getUserMessg, function () {
                    $storage.name = $scope.getUserMessg.name;
                    input_alert('修改成功', 1000);
                    setTimeout(function () {
                        $state.go("ucboot.myview")
                    }, 1000)
                }, function () {

                })
            }
        }
    }])
    .controller('UserpointController', ['$scope', '$stateParams', 'AuthService', function ($scope, $stateParams, AuthService) {
        $scope.points={
            points:0,
            };
        AuthService.getUserpoints().$promise.then(function (data) {
            $scope.points = data
        });
    }])
    .controller('ChangepointController', ['$scope', '$stateParams', 'AuthService', function ($scope, $stateParams, AuthService) {
        $scope.points={};
        AuthService.getUserpoints().$promise.then(function (data) {
            $scope.points = data;
        });
        $scope.change = function () {
            if ($scope.exchange > $scope.points.points) {
                alert("积分不足")
                $scope.exchange = 10000;
            }
            else if ($scope.exchange > 0) {
                document.getElementById("exchangemony").removeAttribute("disabled");
                document.getElementById("exchangemony").style.backgroundColor = 'rgb(48, 174, 79)';
                document.getElementById("exchangemony").style.cursor = "pointer";
            }
            else {
                document.getElementById("exchangemony").setAttribute("disabled", "disabled");
                document.getElementById("exchangemony").style.backgroundColor = 'rgb(94,94,94)';
                document.getElementById("exchangemony").style.cursor = "not-allowed";
            }
        }
        $scope.exchangemony = function () {
            if ($scope.exchange == undefined || $scope.exchange < 10000) {
                alert("提现至少需要10000积分")
                $scope.exchange = 10000;
            }
            else {
                AuthService.exchangemony($scope.exchange, function () {
                    alert("兑换积分成功，请到余额查看")
                    $scope.points.points -= $scope.exchange;
                })
            }
        }

    }])
